package com.shoutao.website.utils;


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by cqin on 2017/8/7.
 */
public final class SqlToString {

    /**
     * 隐藏构造方法
     */
    private SqlToString() {

    }

    public static String file2String(String fileName) {
        InputStream stream = SqlToString.class.getClassLoader().getResourceAsStream(fileName);
        return file2String(stream);
    }

    /**
     * @param stream
     * @return
     */
    private static String file2String(InputStream stream) {
        String encoding = "utf-8";
        StringBuilder result = new StringBuilder();
        if (stream != null) { //判断文件是否存在
            String lineTxt = null;
            try (
                    InputStreamReader read = new InputStreamReader(stream, encoding);
                    BufferedReader bufferedReader = new BufferedReader(read)) {
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    result.append(lineTxt + "\t");//为了防止换行出现不识别的情况， 故此处对每一行都加上空格
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        System.out.println("--------------" + result.toString());
        return result.toString();
    }
}
